<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>代收业务变更页面</title>
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <style>
        .layui-form-label {
            width: 100px;
        }
        .layui-form-item {
            margin-top: 10px;
        }
        .layui-disabled {
            color: black!important;
        }
        .lform {
            width: 300px;
        }
        .sform {
            width: 100px;
        }
    </style>
</head>
<body>
<input id="hidValue2" type="hidden">
<form class="layui-form" id="addForm" lay-filter="addForm" style="padding-top: 20px;">
    <input id="gmid2" name="gmid" type="hidden">
    <div class="layui-form-item layui-inline" style="margin-bottom: 0px;">
        <label class="layui-form-label">货运单编号</label>
        <div class="layui-inline">
            <input id="goodsBillCode2" class="layui-input lform layui-disabled" readonly="readonly"/>
        </div>
    </div>
    <div class="layui-form-item layui-inline" style="margin-bottom: 0px;">
        <label class="layui-form-label">客户名称</label>
        <div class="layui-inline">
            <input id="sendGoodsCustomer2" class="layui-input layui-disabled" readonly="readonly"/>
        </div>
    </div>
    <div class="layui-form-item layui-inline" style="margin-bottom: 0px;">
        <label class="layui-form-label">输入货款(元)</label>
        <div class="layui-inline">
            <input id="helpAcceptPayment2" name="helpAcceptPayment" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item layui-inline" style="margin-bottom: 0px;">
        <label class="layui-form-label">选择业务</label>
        <div class="layui-inline" id="selectBusiness2">
            <select id="sendGoodsCustomerMobile2" name="sendGoodsCustomerMobile" class="shortinput">
                <option value="" selected="selected" disabled="disabled">--请选择--</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item text-right" style="margin-top: 20px;text-align: center;">
            <button class="layui-btn" lay-filter="addSubmit" lay-submit>保存</button>
            <button class="layui-btn layui-btn-primary" id="closebutton" type="button" >取消</button>
    </div><!--ew-event="closeDialog"-->
</form>
<script src="../../../layuiadmin/layui/layui.js"></script>
<script>
    // 要使用的layui模块
    layui.use(['layer', 'form'], function () {
        var layer = layui.layer; // 获得layer模块
        var form = layui.form; // 获得form模块
        var $ = layui.$; // 调用JQuery方法时

        // 取值
        var adddata = JSON.parse($("#hidValue2").val());

        // 表单赋值
        $('#gmid2').val(adddata.gmid);
        $('#goodsBillCode2').val(adddata.goodsBillCode);// 货单号
        $('#sendGoodsCustomer2').val(adddata.sendGoodsCustomer);// 发货客户姓名

        // 提示
        layer.tips('货款需大于0', '#helpAcceptPayment2', {
            tips: [3, '#3595CC'],
            tipsMore: true,
            time: 2000
        });
        layer.tips('需选择业务类型', '#selectBusiness2', {
            tips: [3, '#3595CC'],
            tipsMore: true,
            time: 2000
        });

        // 监听关闭
        $('#closebutton').click(function () {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        })


        form.on('submit(addSubmit)', function(data){
            layer.confirm('您确认要添加代收业务吗？', {
                btn: ['确认','取消'] //按钮
            }, function(){
                // $("#changeForm").submit();//重点一！！！模拟提交！！
                var index = parent.layer.getFrameIndex(window.name);

                // alert(JSON.stringify(data.field.goodsBillCode));
                // alert(data.field.goodsBillCode);

                // console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
                // console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
                // console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
                $.ajax({
                    url: 'http://localhost:9000/settlement/collection/businessAdd',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        "gmid": data.field.gmid,// 主键
                        "helpAcceptPayment": data.field.helpAcceptPayment, // 货款
                        "sendGoodsCustomerMobile": data.field.sendGoodsCustomerMobile // 业务类型
                    },
                    success: function(result) {
                        if(result.msg.indexOf("成功") == -1){
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 1500
                            });
                        }else{
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1500
                            });
                            setTimeout(function() {
                                /* 关闭弹出层 */
                                parent.layer.close(index);
                                /* 刷新父页面中的表格 */
                                parent.layui.table.reload('changeTable');
                                /* 刷新父页面 */
                                // parent.location.reload();
                            }, 2000);
                        }
                    }
                });
            }, function(){
                layer.msg('已取消..');
                return false;
            });
            return false;//重点二！！！！  阻止提交行为！！
        });

        // 监听提交
        // form.on('submit(addSubmit)', function(data) {
        //
        // });
    });
</script>
</body>
</html>